import { CoolController, BaseController } from '@cool-midway/core';
import { GoodsPromoMzEntity } from '../../entity/promo_mz';
import { GoodsPromoMzService } from '../../service/promo_mz.service';
import { Body, Inject, Post } from '@midwayjs/core';

/**
 * 促销买赠管理
 */
@CoolController({
  api: ['page', 'info'],
  entity: GoodsPromoMzEntity,
  service: GoodsPromoMzService,
  pageQueryOp: {
    keyWordLikeFields: ['a.goodsId', 'a.freeId'],
    fieldEq: ['a.status', 'a.billNo'],
    addOrderBy: {
      createTime: 'desc',
    },
  },
})
export class AdminGoodsPromoMzController extends BaseController {
  @Inject()
  goodsPromoMzService: GoodsPromoMzService;

  @Post('/getByBillNo')
  async getByBillNo(@Body() params: { billNo: string }) {
    return this.ok(await this.goodsPromoMzService.getByBillNo(params.billNo));
  }

  @Post('/getByGoodsId')
  async getByGoodsId(@Body() params: { goodsId: string }) {
    return this.ok(await this.goodsPromoMzService.getByGoodsId(params.goodsId));
  }

  @Post('/getAllActiveDetails')
  async getAllActiveDetails() {
    return this.ok(await this.goodsPromoMzService.getAllActiveDetails());
  }
} 